package com.cychat.mall.controller;

import com.Cychat.commons.entity.ResultMessage;
import com.Cychat.commons.entity.pojo.OrderDetail;
import com.cychat.mall.service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Auther: 刘俊  <br/>
 * Date: 2025-11-7:下午 5:36  <br/>
 * Description: 订单详情控制器
 */
@RestController
@RequestMapping("/api/mall")
@CrossOrigin
public class OrderDetailController {
    @Autowired
    private OrderDetailService orderDetailService;
    //根据订单id查询订单详情
    @GetMapping("/orderDetail/list/{userId}")
    public ResultMessage<List<OrderDetail>> getOrderDetail(@PathVariable("userId") Long userId, @RequestParam("orderId") String orderId) {
        try {
            //根据订单id查询订单详情,并返回订单详情列表
            List<OrderDetail> orderDetails = orderDetailService.lambdaQuery()
                    .eq(OrderDetail::getOrderId, orderId)
                    .list();
            return ResultMessage.success(orderDetails);
        } catch (Exception e) {
            return ResultMessage.error("查询订单详情失败");
        }
    }
}
